﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using JumbotPay.API.WxPayAPI;

namespace JumbotPay.WebFile.Wxpay_Mobile
{
    public partial class _default_step2 : JumbotPay.UI.BasicPage
    {
        /// <summary>
        /// 调用js获取收货地址时需要传入的参数
        /// 格式：json串
        /// 包含以下字段：
        ///     appid：公众号id
        ///     scope: 填写“jsapi_address”，获得编辑地址权限
        ///     signType:签名方式，目前仅支持SHA1
        ///     addrSign: 签名，由appid、url、timestamp、noncestr、accesstoken参与签名
        ///     timeStamp：时间戳
        ///     nonceStr: 随机字符串
        /// </summary>
        public string account_wxpay;
        protected void Page_Load(object sender, EventArgs e)
        {
            account_wxpay = q("account_no");
            string order_id = q("order_id");
            if (!IsPostBack)
            {
                JsApiPay jsApiPay = new JsApiPay(this);
                try
                {
                    //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                    string redirect_url = site.Url + "/wxpay_mobile/default_step2.aspx?account_no=" + account_wxpay + "&order_id=" + order_id;
                    jsApiPay.GetOpenidAndAccessToken(account_wxpay, redirect_url);
                    ViewState["openid"] = jsApiPay.openid;
                    string openid = jsApiPay.openid;
                    JumbotPay.Utils.Logs.Debug("wxpayM_get_opeid", ViewState["openid"].ToString(), false);
                    string url = "default_step3.aspx?account_no=" + account_wxpay + "&openid=" + openid + "&order_id=" + order_id;
                    Response.Redirect(url);
                }
                catch (Exception ex)
                {
                    JumbotPay.Utils.Logs.Error("wxpayM_get_opeid", "" + ex);
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错，请重试" + "</span>");
                }
            }
        }

 
    }
}